<?php
/**
 *体征测量次数模型
 * Created by PhpStorm.
 * User: zhang-hong
 * Date: 2017/3/8
 * Time: 14:29
 */
class ZhuyuanFareLevelModel extends BaseModel
{

    //获取体征应该测量次数
    public function GetZhuyuanFareLeveData($zhuyuan_id,$yiyuan_id)
    {
        $times = DB::select("times")
            ->from("zhuyuan_fare_level")
            ->where("zhuyuan_id","=",$zhuyuan_id)
            ->and_where("yiyuan_id","=",$yiyuan_id)
            ->execute()
            ->get("times",1);
        return $times;
    }
    //术后信息
    public function GatZhuyuanTizheng($zhuyuan_id,$yiyuan_id)
    {
        $jiancha_value = DB::select("jiancha_value")
            ->from("zhuyuan_tizheng")
            ->where("zhuyuan_id","=",$zhuyuan_id)
            ->and_where("yiyuan_id","=",$yiyuan_id)
            ->and_where("jiancha_type","=","操作")
            ->and_where("jiancha_fangshi","=","手术")
            ->execute()
            ->get("jiancha_value","");
        return $jiancha_value;
    }

    /**
     * 计算指定日期到当前日期的天数
     * @param  [type] $date [description]
     * @return [type]       [description]
     */
    public function zpd_date_diff($date)
    {
        /*计算天数*/
        $datetime1 = date_create(substr($date, 0, 10));
        $datetime2 = date_create(date('Y-m-d'));
        $interval  = date_diff($datetime1, $datetime2);
        return $interval->format('%a');
    }

    /**
     * 根据指定日期获取已测量次数，默认为当天
     * @param  [type] $zhuyuan_id [description]
     * @param  [type] $date       [description]
     * @return [type]             [description]
     */
    public static function get_has_times($zhuyuan_id, $yiyuan_id,$date="")
    {
        if (empty($date)) {
            $date = "NOW()";
        }

        $jiancha_value = DB::select(array("count(1)","total"))
            ->from("zhuyuan_fare_log")
            ->where("zhuyuan_id","=",$zhuyuan_id)
            ->and_where("yiyuan_id","=",$yiyuan_id)
            ->and_where("TO_DAYS(jiancha_time)","=","TO_DAYS($date)")
            ->execute()
            ->get("total",0);
        return $jiancha_value;
    }
    //获取检查报告
    public function getPascJiancha($jiancha_id,$yiyuan_id)
    {
        $data = DB::select()
            ->from("pacs_jiancha_info")
            ->where("id","=",$jiancha_id)
            ->and_where("yiyuan_id","=",$yiyuan_id)
            ->execute()
            ->as_array();
        return $data;
    }
}